package com.licg.chatroom.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
 * 判断是否登录的filter
 * Servlet Filter implementation class LoginSessionFilter
 */
public class LoginSessionFilter implements Filter {
	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {

	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest servletRequest,
			ServletResponse servletResponse, FilterChain chain)
			throws IOException, ServletException {
//		HttpServletRequest request = (HttpServletRequest) servletRequest;
//		System.out.println(request.getRequestURI());
//		HttpServletResponse response = (HttpServletResponse) servletResponse;
//		// 如果是登陆页面以及登陆操作//不作处理
//		if (request.getRequestURI().endsWith("login.html")
//				|| request.getRequestURI().endsWith("login")) {
//			chain.doFilter(servletRequest, response);
//		}
//			// 判断session是否存在或者用户是否登陆
//			HttpSession session = request.getSession(false);
//			if (session == null||session.getAttribute("username").equals(null)||session.getAttribute("username").equals("")) {
////				response.sendRedirect("/login.html");
//				return;
//			}

			chain.doFilter(servletRequest, servletResponse);
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
	}

}
